<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible"
  >
    <el-form
      :model="dataForm"
      :rules="dataRule"
      ref="dataForm"
      @keyup.enter.native="dataFormSubmit()"
      label-width="100px"
    >
      <!-- <el-form-item label="用户id" prop="userId">
      <el-input v-model="dataForm.userId" placeholder="用户id"></el-input>
      </el-form-item>-->
      <div style="margin-left:30px;">
        <p>
          <span>Uid:</span>
          <span>{{dataForm.userId}}</span>
        </p>
        <p>
          <span>昵称:</span>
          <span>{{dataForm.nickname}}</span>
        </p>
        <p>
          <span>头像:</span>
          <span>
            <img :src="dataForm.avatar" style="width:40px;height:40px;" />
          </span>
        </p>
        <p>
          <span>手机号:</span>
          <span>{{dataForm.phone}}</span>
        </p>
        <p>
          <span>微信号:</span>
          <span>{{dataForm.wxNumber}}</span>
        </p>
        <p>
          <span>二维码:</span>
          <span>
            <img :src="dataForm.wxQrcode" style="width:40px;height:40px;" />
          </span>
        </p>
        <p>
          <span>注册时间:</span>
          <span>{{dataForm.gmtCreate}}</span>
        </p>
        <p>
          <span>最后登录时间:</span>
          <span>{{dataForm.lastLoginAt}}</span>
        </p>
        <p>
          <span>会员购买时间:</span>
          <span>{{dataForm.memberStartTime}}</span>
        </p>
      </div>
      <el-form-item label="会员状态" prop="memberStatus">
        <el-radio v-model="dataForm.memberStatus" label="1">未过期</el-radio>
        <el-radio v-model="dataForm.memberStatus" label="0">过期</el-radio>
      </el-form-item>
      <el-form-item label="会员到期日" prop="memberEndTime">
        <template>
          <el-date-picker
            style="width:250px;"
            v-model="dataForm.memberEndTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="会员到期日"
          ></el-date-picker>
        </template>
      </el-form-item>
      <el-form-item label="会员身份" prop="grade">
        <el-radio v-model="dataForm.grade" label="1">会员</el-radio>
        <el-radio v-model="dataForm.grade" label="2">经理</el-radio>
        <el-radio v-model="dataForm.grade" label="3">总监</el-radio>
      </el-form-item>
      <el-form-item label="状态" prop="isForbidden">
        <el-radio v-model="dataForm.isForbidden" label="1">正常</el-radio>
        <el-radio v-model="dataForm.isForbidden" label="0">冻结</el-radio>
      </el-form-item>
      <el-form-item label="职位" prop="title">
        <el-radio v-model="dataForm.title" label="0">班长</el-radio>
        <el-radio v-model="dataForm.title" label="1">班主任</el-radio>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      dataForm: {
        id: 0,
        userId: "",
        nickname: "",
        phone: "",
        wxNumber: "",
        avatar: "",
        lastLoginAt: "",
        gmtCreate: "",
        isMember: "",
        memberStartTime: "",
        wxQrcode: "",
        memberEndTime: "",
        isForbidden: "1",
        memberStatus: "1",
        grade: "1",
        title:'',
      },
      dataRule: {}
    };
  },
  methods: {
    init(userId) {
      this.dataForm.id = userId || 0;
      this.visible = true;
      this.$nextTick(() => {
        this.$refs["dataForm"].resetFields();
        document.getElementsByTagName("span").innerHTML = "";
        document.getElementsByTagName("img").innerHTML = "";
        if (this.dataForm.id) {
          this.$http({
            url: this.$http.adornUrl(`/user/appuser/info/${this.dataForm.id}`),
            method: "get",
            params: this.$http.adornParams()
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.dataForm.userId = data.memberInfoVo.userId;
              this.dataForm.nickname = data.memberInfoVo.nickname;
              this.dataForm.phone = data.memberInfoVo.phone;
              this.dataForm.wxNumber = data.memberInfoVo.wxNumber;
              this.dataForm.avatar = data.memberInfoVo.avatar;
              this.dataForm.isForbidden = data.memberInfoVo.isForbidden + "";
              this.dataForm.lastLoginAt = data.memberInfoVo.lastLoginAt;
              this.dataForm.memberStartTime = data.memberInfoVo.memberStartTime;
              this.dataForm.memberEndTime = data.memberInfoVo.memberEndTime;
              this.dataForm.memberStatus = data.memberInfoVo.memberStatus + "";
              this.dataForm.wxQrcode = data.memberInfoVo.wxQrcode;
              this.dataForm.grade = data.memberInfoVo.grade + "";
              this.dataForm.gmtCreate = data.memberInfoVo.gmtCreate;
              this.dataForm.title = data.memberInfoVo.title+''
            }
          });
        }
      });
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs["dataForm"].validate(valid => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl(`/user/appuser/update`),
            method: "post",
            data: this.$http.adornData({
              userId: this.dataForm.id,
              memberStatus: this.dataForm.memberStatus,
              memberEndTime: this.dataForm.memberEndTime,
              grade: this.dataForm.grade,
              isForbidden: this.dataForm.isForbidden,
              title:this.dataForm.title,
            })
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.$message({
                message: "操作成功",
                type: "success",
                duration: 1500,
                onClose: () => {
                  this.visible = false;
                  this.$emit("refreshDataList");
                }
              });
            } else {
              this.$message.error(data.msg);
            }
          });
        }
      });
    }
  }
};
</script>
